package com.sh.data.engine.domain.normalization.standard.model.domain;

import lombok.Data;

import java.math.BigDecimal;

/**
 * @author boyue.wjl
 */
@Data
public class MappingReportDomain {
    private Long id;

    private Long tblId;

    private String tblName;

    private String tblDes;

    private String hitStr;

    private String percentStr;

    private Integer hitCount;

    private Integer fieldCount;

    public void initHitStr() {
        int hit = hitCount == null ? 0 : hitCount;
        int count = fieldCount == null ? 0 : fieldCount;
        hitStr = hit + "/" + count;
    }

    public void initPercentStr() {
        int hit = hitCount == null ? 0 : hitCount;
        int count = fieldCount == null ? 0 : fieldCount;
        if (count == 0) {
            percentStr = "0%";
        } else {
            double doubleValue =
                new BigDecimal(hit * 100.0 / count).setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue();
            String temp = doubleValue + "";
            temp = temp.replaceAll("0+?$", "");
            temp = temp.replaceAll("[.]$", "");
            temp = doubleValue + "%";
            percentStr = temp;
        }
    }
}
